package com.example.service.impl;

import com.example.respdto.resultDTO;
import com.example.service.uploadService;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Service
public class uploadServiceImpl implements uploadService {
    private  static  Logger logger = LoggerFactory.getLogger(uploadServiceImpl.class);
    @Override
    public resultDTO upload(MultipartFile file)  {

        String originalFilename = file.getOriginalFilename();
        String fileName = System.currentTimeMillis()+"."+originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        String path="D:\\teach\\";
        String filePath=path+fileName;
        File file1 = new File(filePath);
        if(!file1.getParentFile().exists()){
            file1.getParentFile().mkdirs();
        }
        try {
            file.transferTo(file1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("上传文件成功，文件路径为：{}",file1);
        return  resultDTO.success(file1);
    }

    @Override
    public resultDTO downLoad(File file) {
        return null;
    }
}
